
import java.io.*;

public class SafeExtraFastCopy2 {

   static final int BUFF_SIZE = 100000;
   static final byte[] buffer = new byte[BUFF_SIZE];

   public static void copy(String from, String to) 
   throws IOException{
      InputStream in = null;
      OutputStream out = null; 
      try {
         in = new FileInputStream(from);
         out = new FileOutputStream(to);
         while (true) {
            synchronized (buffer) {
               int amountRead = in.read(buffer);
               if (amountRead == -1) {
                  break;
               }
               out.write(buffer, 0, amountRead); 
            }
         } 
      } finally {
         if (in != null) {
            in.close();
         }
         if (out != null) {
            out.close();
         }
      }
   }

   public static void main(String[] args) {
      try {
         Stopwatch timer = new Stopwatch().start();
         for (int i = 0; i < 20; i++) {
            copy(args[0], args[1]);
         }
         timer.stop();
         System.out.println(timer.getElapsedTime()/20);
      } catch (IOException e) {
         e.printStackTrace();
      }
   }
}   
